﻿using ProtoBuf;
using System;
using System.Collections.Generic;
using UnityEngine;

public class Action1001 : BaseAction
{
    private ActionResult actionResult;
    private Response1001Pack _responseData;

    public Action1001()
        : base(1001)
    {
    }

    protected override void SendParameter(NetWriter writer, ActionParam actionParam)
    {
        writer.writeInt32("PageIndex", actionParam.Get<int>("PageIndex"));
        writer.writeInt32("PageSize", actionParam.Get<int>("PageSize"));
    }

    protected override void DecodePackage(NetReader reader)
    {
        if (!reader.Success)
        {
            Debug.LogError(string.Format("Action {0} error {1}-{2}", reader.ActionId, reader.StatusCode, reader.Description));
            return;
        }
        actionResult = new ActionResult();

        //actionResult["UserName"] = reader.readString();
        //actionResult["Score"] = reader.getInt();

        //默认Scut流格式解包
        _responseData = new Response1001Pack();
        _responseData.PageCount = reader.getInt();
        int nNum = reader.getInt();
        _responseData.Items = new List<RankData>();
        for (int i = 0; i < nNum; i++)
        {
            reader.recordBegin();
            RankData item = new RankData();
            item.UserName = reader.readString();
            item.Score = reader.getInt();
            reader.recordEnd();
            _responseData.Items.Add(item);
        }

    }

    public override ActionResult GetResponseData()
    {
        return actionResult;
    }
}

[ProtoContract]
public class Response1001Pack
{
    [ProtoMember(102)]
    public List<RankData> Items { get; set; }
    [ProtoMember(101)]
    public int PageCount { get; set; }
}

[ProtoContract]
public class RankData
{
    [ProtoMember(102)]
    public int Score { get; set; }
    [ProtoMember(101)]
    public string UserName { get; set; }
}
